package com.ctsi.ssdc.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
@Slf4j
public class ExcelSpeedInfoAOP {

    @Pointcut(value = "@annotation(com.ctsi.ssdc.aop.TimeCostLog)")
    public void pointCut() {}

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint pj) {
        long start = System.currentTimeMillis();
        MethodSignature signature = (MethodSignature) pj.getSignature();
        Method method = signature.getMethod();
        Object proceed = null;
        try {
            proceed = pj.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        log.info("\n=====================================================" +
                "\n\t\t方法: {}, 本次执行花费: {} ms" +
                "\n=====================================================",method.getName(),end-start);
        return proceed;
    }


}
